#include <my_header.h>

#define LOG_COMMAND(user_id,command,ret,fd)\
    do{\
        time_t now = time(NULL);\
        struct tm *local_time = localtime(&now);\
        char buf[1024] = { 0 };\
        sprintf(buf, " %04d年%02d月%02d日 %02d:%02d:%02d ",local_time->tm_year + 1900,\
                local_time->tm_mon + 1,\
                local_time->tm_mday,\
                local_time->tm_hour,\
                local_time->tm_min,\
                local_time->tm_sec);\
        strcat(buf, user_id);\
        strcat(buf, "  ");\
        switch(command){\
        case 0:\
               strcat(buf, "exit");\
            break;\
        case 1:\
               strcat(buf, "cd");\
            break;\
        case 2:\
               strcat(buf, "ls");\
            break;\
        case 3:\
               strcat(buf, "puts");\
            break;\
        case 4:\
               strcat(buf, "gets");\
            break;\
        case 5:\
               strcat(buf, "pwd");\
            break;\
        case 6:\
               strcat(buf, "rm");\
            break;\
        case 7:\
               strcat(buf, "mkdir");\
            break;\
        }\
        if(ret == -1){\
            strcat(buf, "  命令输入错误\n");\
        } else{\
            strcat(buf, "  命令输入正确\n");\
        }\
        write(fd, buf, strlen(buf));\
        \
    }while(0)


#define LOG_ERROR(ret,error_flag,msg,fd)\
    do{\
        time_t now = time(NULL);\
        struct tm *local_time = localtime(&now);\
        char buf[1024] = { 0 };\
        sprintf(buf, " %04d年%02d月%02d日 %02d:%02d:%02d ",local_time->tm_year + 1900,\
                local_time->tm_mon + 1,\
                local_time->tm_mday,\
                local_time->tm_hour,\
                local_time->tm_min,\
                local_time->tm_sec);\
            strcat(buf, "  ");\
            strcat(buf, "  ");\
            if(ret == error_flag){\
                strcat(buf, msg);\
            }\
        strcat(buf, "\n");\
        write(fd, buf, strlen(buf));\
    }while(0);
